import Foundation
import MBProgressHUD
extension MBProgressHUD {
    static let displayTime = 2.0

    static func show(message: String) {
        guard let view = getUIWindow() else {
            return 
        }
        MBProgressHUD.hide(for: view, animated: false)
        let hud = MBProgressHUD.showAdded(to: view, animated: true)
        hud.removeFromSuperViewOnHide = true
        hud.isUserInteractionEnabled = false
        hud.mode = .text
        hud.label.numberOfLines = 0
        hud.label.text = message
        hud.offset = CGPoint(x: 0, y: -80)
        hud.hide(animated: true, afterDelay: MBProgressHUD.displayTime)
    }

    private static func getUIWindow() -> UIWindow? {
        return UIApplication.shared.windows.first {
            type(of: $0) === UIWindow.self
        }
    }
}

